﻿#include "OrderHistoryDialog.h"
#include "ChangeTicketDialog.h"
#include <Global_Class.h>
#include <orders.h>
#include <seats.h>
#include <stations.h>
#include <trains.h>
#include <QMessageBox>
#include <Constants.h>
using namespace Constants;

//OrderHistoryDialog::OrderHistoryDialog(const users& user, QWidget* parent, bool enableRefundAndChange) : QDialog(parent) {
//    // 先刷新订单数据，保证每次进入页面都获取最新订单历史
//    allData->Order_ReadFromFile(ORDER_INFORMATION_FILE_POSITION);
//    setWindowTitle("历史订单查询");
//    resize(1000, 400); // 增加宽度以容纳票价
//    QVBoxLayout* layout = new QVBoxLayout(this);
//    QTableWidget* table = new QTableWidget(this);
//    int colCount = enableRefundAndChange ? 11 : 9;
//    table->setColumnCount(colCount);
//	table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 设置表格不可编辑
//    if (enableRefundAndChange) {
//        table->setHorizontalHeaderLabels({"订单号", "车次", "出发站", "到达站", "座位号", "日期", "订单状态", "下单时间", "票价", "退票", "改签"});
//    } else {
//        table->setHorizontalHeaderLabels({"订单号", "车次", "出发站", "到达站", "座位号", "日期", "订单状态", "下单时间", "票价"});
//    }
//    table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
//    table->horizontalHeader()->setSectionResizeMode(7, QHeaderView::ResizeToContents);
//    int row = 0;
//    std::string userId = user.getUserId();
//    bool hasOrder = false;
//    for (auto& order : allData->ordersQueue) {
//        if (std::to_string(order.getUserId()) == userId) {
//            hasOrder = true;
//            table->insertRow(row);
//            table->setItem(row, 0, new QTableWidgetItem(QString::number(order.getOrderId())));
//            QString trainCode = "";
//            for (const auto& train : allData->trainQueue) {
//                if (train.getTrainId() == order.getTrainId()) {
//                    trainCode = QString::fromStdString(train.getTrainCode());
//                    break;
//                }
//            }
//            table->setItem(row, 1, new QTableWidgetItem(trainCode));
//            QString startStation = "";
//            for (const auto& st : allData->stationsQueue) {
//                if (st.getStationId() == order.getStartStationId()) {
//                    startStation = QString::fromStdString(st.getName());
//                    break;
//                }
//            }
//            table->setItem(row, 2, new QTableWidgetItem(startStation));
//            QString endStation = "";
//            for (const auto& st : allData->stationsQueue) {
//                if (st.getStationId() == order.getEndStationId()) {
//                    endStation = QString::fromStdString(st.getName());
//                    break;
//                }
//            }
//            table->setItem(row, 3, new QTableWidgetItem(endStation));
//            QString seatNo = "";
//            std::string seatType = "";
//            for (const auto& seat : allData->seatsQueue) {
//                if (seat.getSeatId() == order.getSeatId()) {
//                    seatNo = QString::fromStdString(seat.getSeatNo());
//                    seatType = seat.getSeatType();
//                    break;
//                }
//            }
//            table->setItem(row, 4, new QTableWidgetItem(seatNo));
//            table->setItem(row, 5, new QTableWidgetItem(QString::fromStdString(order.getTravelDate())));
//            QString statusStr = "";
//            switch (order.getStatus()) {
//                case orders::booked: statusStr = "已预订"; break;
//                case orders::canceled: statusStr = "已退票"; break;
//                case orders::changed: statusStr = "已改签"; break;
//                default: statusStr = "未知"; break;
//            }
//            table->setItem(row, 6, new QTableWidgetItem(statusStr));
//            table->setItem(row, 7, new QTableWidgetItem(QString::fromStdString(order.getOrderTime())));
//            // 票价列
//            // double price = order.getPrice();
//            double price = order.getPrice()>=0 ? order.getPrice(): AllData::CalculateTicketPrice(order.getStartStationId(), order.getEndStationId(), seatType, allData->stationsQueue);
//            table->setItem(row, 8, new QTableWidgetItem(price < 0 ? "-" : QString::number(price, 'f', 2)));
//            if (enableRefundAndChange) {
//                QPushButton* btnRefund = new QPushButton("退票");
//                QPushButton* btnChange = new QPushButton("改签");
//                if (order.getStatus() != orders::booked) {
//                    btnRefund->setEnabled(false);
//                    btnChange->setEnabled(false);
//                }
//                table->setCellWidget(row, 9, btnRefund);
//                table->setCellWidget(row, 10, btnChange);
//                connect(btnRefund, &QPushButton::clicked, this, [this, &order, table, row]() {
//                    if (order.getStatus() != orders::booked) {
//                        QMessageBox::warning(this, "退票失败", "该订单不可退票");
//                        return;
//                    }
//                    int ret = QMessageBox::question(this, "确认退票", "确定要退票吗？", QMessageBox::Yes | QMessageBox::No);
//                    if (ret != QMessageBox::Yes) return;
//                    order.setStatus(orders::canceled);
//                    // 释放座位占用记录
//                    auto& queue = allData->seatOccupyQueue;
//                    queue.erase(std::remove_if(queue.begin(), queue.end(), [&](const SeatOccupy& so) {
//                        return so.getOrderId() == order.getOrderId();
//                    }), queue.end());
//                    allData->SeatOccupy_WriteToFile("seat_occupy.txt");
//                    allData->Order_WriteToFile(ORDER_INFORMATION_FILE_POSITION);
//                    allData->Seat_WriteToFile(SEAT_INFORMATION_FILE_POSITION);
//                    table->setItem(row, 6, new QTableWidgetItem("已退票"));
//                    table->cellWidget(row, 9)->setEnabled(false);
//                    table->cellWidget(row, 10)->setEnabled(false);
//                    QMessageBox::information(this, "退票成功", "退票成功，座位已释放");
//                });
//                connect(btnChange, &QPushButton::clicked, this, [this, &order, table, row, thisUser=user]() {
//                    if (order.getStatus() != orders::booked) {
//                        QMessageBox::warning(this, "改签失败", "该订单不可改签");
//                        return;
//                    }
//                    int ret = QMessageBox::question(this, "确认改签", "确定要改签吗？", QMessageBox::Yes | QMessageBox::No);
//                    if (ret != QMessageBox::Yes) return;
//                    ChangeTicketDialog dlg(order, this);
//                    if (dlg.exec() == QDialog::Accepted && dlg.isSuccess()) {
//                        // 改签业务逻辑
//                        // 1. 原订单状态设为已改签
//                        order.setStatus(orders::changed);
//                        // 释放原座位占用记录
//                        //auto& queue = allData->seatOccupyQueue;
//                        //queue.erase(std::remove_if(queue.begin(), queue.end(), [&](const SeatOccupy& so) {
//                        //    return so.getOrderId() == order.getOrderId();
//                        //}), queue.end());
//                        //allData->SeatOccupy_WriteToFile("seat_occupy.txt");
//                        // 2. 写入文件
//                        allData->Order_WriteToFile(ORDER_INFORMATION_FILE_POSITION);
//                        allData->Seat_WriteToFile(SEAT_INFORMATION_FILE_POSITION);
//                        // 3. 生成新订单
//                        orders newOrder = order;
//                        newOrder.setOrderId(allData->ordersQueue.empty() ? 1 : allData->ordersQueue.back().getOrderId() + 1);
//                        newOrder.setTrainId(dlg.getNewTrainId());
//                        newOrder.setSeatId(dlg.getNewSeatId());
//                        newOrder.setTravelDate(dlg.getNewDate());
//                        newOrder.setStatus(orders::booked);
//                        newOrder.setOrderTime(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss").toStdString());
//                        // 获取新座型
//                        std::string newSeatType;
//                        for (const auto& seat : allData->seatsQueue) {
//                            if (seat.getSeatId() == dlg.getNewSeatId() && seat.getTrainId() == dlg.getNewTrainId()) {
//                                newSeatType = seat.getSeatType();
//                                break;
//                            }
//                        }
//                        // 计算新订单的票价
//                        double newPrice = AllData::CalculateTicketPrice(newOrder.getStartStationId(), newOrder.getEndStationId(), newSeatType, allData->stationsQueue);
//                        newOrder.setPrice(newPrice);
//                        // 4. 添加新订单到队列
//                        allData->ordersQueue.push_back(newOrder);
//                        allData->Order_WriteToFile(ORDER_INFORMATION_FILE_POSITION);
//                        table->setItem(row, 6, new QTableWidgetItem("已改签"));
//                        table->cellWidget(row, 9)->setEnabled(false);
//                        table->cellWidget(row, 10)->setEnabled(false);
//                        QMessageBox::information(this, "改签成功", QString("改签成功，新订单号：%1").arg(newOrder.getOrderId()));
//                    }
//                });
//            }
//            row++;
//        }
//    }
//    if (!hasOrder) {
//        table->setRowCount(1);
//        table->setItem(0, 0, new QTableWidgetItem("您还没有历史订单"));
//        for (int i = 1; i < colCount; ++i) table->setItem(0, i, new QTableWidgetItem(""));
//    }
//    layout->addWidget(table);
//    setLayout(layout);
//}

//以下是UI优化后的版本欧~--------------------------------------------------------------------------------
OrderHistoryDialog::OrderHistoryDialog(const users& user, QWidget* parent, bool enableRefundAndChange) : QDialog(parent) {
    // 先刷新订单数据，保证每次进入页面都获取最新订单历史
    allData->Order_ReadFromFile(ORDER_INFORMATION_FILE_POSITION);
    setWindowTitle("历史订单查询");
    setMinimumSize(1200, 500); // 增加尺寸以容纳更多内容
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

    // 设置字体
    QFont globalFont("Microsoft YaHei", 10);
    QFont headerFont("Microsoft YaHei", 10, QFont::Bold);
    setFont(globalFont);

    // 主布局
    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    mainLayout->setContentsMargins(20, 20, 20, 20);
    mainLayout->setSpacing(15);

    // === 标题区域 ===
    QLabel* titleLabel = new QLabel("历史订单查询", this);
    titleLabel->setFont(QFont("Microsoft YaHei", 14, QFont::Bold));
    titleLabel->setStyleSheet("color: #2c3e50; padding: 8px 0;");
    titleLabel->setAlignment(Qt::AlignCenter);
    mainLayout->addWidget(titleLabel);

    // === 表格区域 ===
    QFrame* tableFrame = new QFrame(this);
    tableFrame->setFrameStyle(QFrame::StyledPanel);
    tableFrame->setStyleSheet("QFrame { background-color: white; border-radius: 8px; }");

    QVBoxLayout* tableLayout = new QVBoxLayout(tableFrame);
    tableLayout->setContentsMargins(12, 12, 12, 12);

    // 表格标题栏
    QHBoxLayout* tableHeaderLayout = new QHBoxLayout();
    QLabel* tableTitle = new QLabel("订单列表", this);
    tableTitle->setFont(headerFont);
    tableTitle->setStyleSheet("color: #34495e;");
    tableHeaderLayout->addWidget(tableTitle);
    tableHeaderLayout->addStretch();

    // 订单统计信息
    QLabel* orderCountLabel = new QLabel("总计: 0 个订单", this);
    orderCountLabel->setStyleSheet("color: #7f8c8d; font-size: 9pt;");
    tableHeaderLayout->addWidget(orderCountLabel);
    tableLayout->addLayout(tableHeaderLayout);

    // 表格控件
    QTableWidget* table = new QTableWidget(this);
    int colCount = enableRefundAndChange ? 11 : 9;
    table->setColumnCount(colCount);
    table->setEditTriggers(QAbstractItemView::NoEditTriggers);

    // 设置表头
    if (enableRefundAndChange) {
        table->setHorizontalHeaderLabels({ "订单号", "车次", "出发站", "到达站", "座位号", "日期", "订单状态", "下单时间", "票价", "退票", "改签" });
    }
    else {
        table->setHorizontalHeaderLabels({ "订单号", "车次", "出发站", "到达站", "座位号", "日期", "订单状态", "下单时间", "票价" });
    }

    // 表格样式优化
    table->horizontalHeader()->setFont(headerFont);
    table->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
    table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
    table->horizontalHeader()->setStretchLastSection(true);

    // 设置列宽
    table->setColumnWidth(0, 100);  // 订单号
    table->setColumnWidth(1, 100);  // 车次
    table->setColumnWidth(2, 120);  // 出发站
    table->setColumnWidth(3, 120);  // 到达站
    table->setColumnWidth(4, 80);   // 座位号
    table->setColumnWidth(5, 110);  // 日期
    table->setColumnWidth(6, 100);   // 订单状态
    table->setColumnWidth(7, 150);  // 下单时间
    table->setColumnWidth(8, 80);   // 票价
    if (enableRefundAndChange) {
        table->setColumnWidth(9, 70);   // 退票
        table->setColumnWidth(10, 70);  // 改签
    }

    table->verticalHeader()->setVisible(false);
    table->setShowGrid(false);
    table->setAlternatingRowColors(true);
    table->setSortingEnabled(true);
    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    table->setSelectionMode(QAbstractItemView::SingleSelection);

    tableLayout->addWidget(table);
    mainLayout->addWidget(tableFrame, 1);

    // === 状态信息区域 ===
    QHBoxLayout* statusLayout = new QHBoxLayout();
    QLabel* infoLabel = new QLabel("双击订单可查看详细信息", this);
    infoLabel->setStyleSheet(
        "QLabel { "
        "    color: #7f8c8d; "
        "    padding: 8px 12px; "
        "    background-color: #ecf0f1; "
        "    border-radius: 4px; "
        "    font-size: 9pt; "
        "}"
    );
    infoLabel->setMinimumHeight(30);
    statusLayout->addWidget(infoLabel);
    mainLayout->addLayout(statusLayout);

    // 填充表格数据
    int row = 0;
    std::string userId = user.getUserId();
    bool hasOrder = false;
    int orderCount = 0;

    // 创建按钮的lambda函数
    auto createActionButton = [this](const QString& text, const QString& color, const QString& hoverColor) {
        QPushButton* btn = new QPushButton(text, this);
        btn->setMinimumSize(60, 28);
        btn->setCursor(Qt::PointingHandCursor);

        QString style = QString(
            "QPushButton { "
            "    background-color: %1; "
            "    color: white; "
            "    border: none; "
            "    border-radius: 4px; "
            "    padding: 4px 8px; "
            "    font-size: 9pt; "
            "    font-weight: bold; "
            "} "
            "QPushButton:hover { "
            "    background-color: %2; "
            "} "
            "QPushButton:pressed { "
            "    background-color: %1; "
            "} "
            "QPushButton:disabled { "
            "    background-color: #bdc3c7; "
            "    color: #7f8c8d; "
            "}"
        ).arg(color, hoverColor);

        btn->setStyleSheet(style);
        return btn;
        };

    for (auto& order : allData->ordersQueue) {
        if (std::to_string(order.getUserId()) == userId) {
            hasOrder = true;
            orderCount++;
            table->insertRow(row);

            // 订单号
            table->setItem(row, 0, new QTableWidgetItem(QString::number(order.getOrderId())));

            // 车次
            QString trainCode = "";
            for (const auto& train : allData->trainQueue) {
                if (train.getTrainId() == order.getTrainId()) {
                    trainCode = QString::fromStdString(train.getTrainCode());
                    break;
                }
            }
            table->setItem(row, 1, new QTableWidgetItem(trainCode));

            // 出发站
            QString startStation = "";
            for (const auto& st : allData->stationsQueue) {
                if (st.getStationId() == order.getStartStationId()) {
                    startStation = QString::fromStdString(st.getName());
                    break;
                }
            }
            table->setItem(row, 2, new QTableWidgetItem(startStation));

            // 到达站
            QString endStation = "";
            for (const auto& st : allData->stationsQueue) {
                if (st.getStationId() == order.getEndStationId()) {
                    endStation = QString::fromStdString(st.getName());
                    break;
                }
            }
            table->setItem(row, 3, new QTableWidgetItem(endStation));

            // 座位号
            QString seatNo = "";
            std::string seatType = "";
            for (const auto& seat : allData->seatsQueue) {
                if (seat.getSeatId() == order.getSeatId()) {
                    seatNo = QString::fromStdString(seat.getSeatNo());
                    seatType = seat.getSeatType();
                    break;
                }
            }
            table->setItem(row, 4, new QTableWidgetItem(seatNo));

            // 日期
            table->setItem(row, 5, new QTableWidgetItem(QString::fromStdString(order.getTravelDate())));

            // 订单状态
            QString statusStr = "";
            QString statusColor = "";
            switch (order.getStatus()) {
            case orders::booked:
                statusStr = "已预订";
                statusColor = "#27ae60"; // 绿色
                break;
            case orders::canceled:
                statusStr = "已退票";
                statusColor = "#e74c3c"; // 红色
                break;
            case orders::changed:
                statusStr = "已改签";
                statusColor = "#3498db"; // 蓝色
                break;
            default:
                statusStr = "未知";
                statusColor = "#95a5a6"; // 灰色
                break;
            }
            QTableWidgetItem* statusItem = new QTableWidgetItem(statusStr);
            statusItem->setForeground(QColor(statusColor));
            table->setItem(row, 6, statusItem);

            // 下单时间
            table->setItem(row, 7, new QTableWidgetItem(QString::fromStdString(order.getOrderTime())));

            // 票价
            double price = order.getPrice() >= 0 ? order.getPrice() :
                AllData::CalculateTicketPrice(order.getStartStationId(), order.getEndStationId(), seatType, allData->stationsQueue);
            QTableWidgetItem* priceItem = new QTableWidgetItem(price < 0 ? "-" : QString::number(price, 'f', 2));
            if (price >= 0) {
                priceItem->setForeground(QColor("#e67e22")); // 橙色显示价格
            }
            table->setItem(row, 8, priceItem);

            if (enableRefundAndChange) {
                // 退票按钮
                QPushButton* btnRefund = createActionButton("退票", "#e74c3c", "#c0392b");
                // 改签按钮
                QPushButton* btnChange = createActionButton("改签", "#3498db", "#2980b9");

                if (order.getStatus() != orders::booked) {
                    btnRefund->setEnabled(false);
                    btnChange->setEnabled(false);
                }

                table->setCellWidget(row, 9, btnRefund);
                table->setCellWidget(row, 10, btnChange);

                // 连接退票按钮信号
                connect(btnRefund, &QPushButton::clicked, this, [this, &order, table, row]() {
                    if (order.getStatus() != orders::booked) {
                        QMessageBox::warning(this, "退票失败", "该订单不可退票");
                        return;
                    }
                    int ret = QMessageBox::question(this, "确认退票",
                        "确定要退票吗？\n退票后座位将被释放。",
                        QMessageBox::Yes | QMessageBox::No);
                    if (ret != QMessageBox::Yes) return;

                    order.setStatus(orders::canceled);
                    // 释放座位占用记录
                    auto& queue = allData->seatOccupyQueue;
                    queue.erase(std::remove_if(queue.begin(), queue.end(), [&](const SeatOccupy& so) {
                        return so.getOrderId() == order.getOrderId();
                        }), queue.end());

                    allData->SeatOccupy_WriteToFile("seat_occupy.txt");
                    allData->Order_WriteToFile(ORDER_INFORMATION_FILE_POSITION);
                    allData->Seat_WriteToFile(SEAT_INFORMATION_FILE_POSITION);

                    // 更新表格显示
                    QTableWidgetItem* statusItem = new QTableWidgetItem("已退票");
                    statusItem->setForeground(QColor("#e74c3c"));
                    table->setItem(row, 6, statusItem);
                    table->cellWidget(row, 9)->setEnabled(false);
                    table->cellWidget(row, 10)->setEnabled(false);

                    QMessageBox::information(this, "退票成功", "退票成功，座位已释放");
                    });

                // 连接改签按钮信号
                connect(btnChange, &QPushButton::clicked, this, [this, &order, table, row, thisUser = user]() {
                    if (order.getStatus() != orders::booked) {
                        QMessageBox::warning(this, "改签失败", "该订单不可改签");
                        return;
                    }
                    int ret = QMessageBox::question(this, "确认改签",
                        "确定要改签吗？\n改签将为您选择新的车次、日期和座位。",
                        QMessageBox::Yes | QMessageBox::No);
                    if (ret != QMessageBox::Yes) return;

                    ChangeTicketDialog dlg(order, this);
                    if (dlg.exec() == QDialog::Accepted && dlg.isSuccess()) {
                        // 改签业务逻辑
                        order.setStatus(orders::changed);
                        allData->Order_WriteToFile(ORDER_INFORMATION_FILE_POSITION);
                        allData->Seat_WriteToFile(SEAT_INFORMATION_FILE_POSITION);

                        // 生成新订单
                        orders newOrder = order;
                        newOrder.setOrderId(allData->ordersQueue.empty() ? 1 : allData->ordersQueue.back().getOrderId() + 1);
                        newOrder.setTrainId(dlg.getNewTrainId());
                        newOrder.setSeatId(dlg.getNewSeatId());
                        newOrder.setTravelDate(dlg.getNewDate());
                        newOrder.setStatus(orders::booked);
                        newOrder.setOrderTime(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss").toStdString());

                        // 获取新座型并计算票价
                        std::string newSeatType;
                        for (const auto& seat : allData->seatsQueue) {
                            if (seat.getSeatId() == dlg.getNewSeatId() && seat.getTrainId() == dlg.getNewTrainId()) {
                                newSeatType = seat.getSeatType();
                                break;
                            }
                        }
                        double newPrice = AllData::CalculateTicketPrice(newOrder.getStartStationId(), newOrder.getEndStationId(), newSeatType, allData->stationsQueue);
                        newOrder.setPrice(newPrice);

                        // 添加新订单
                        allData->ordersQueue.push_back(newOrder);
                        allData->Order_WriteToFile(ORDER_INFORMATION_FILE_POSITION);

                        // 更新表格显示
                        QTableWidgetItem* statusItem = new QTableWidgetItem("已改签");
                        statusItem->setForeground(QColor("#3498db"));
                        table->setItem(row, 6, statusItem);
                        table->cellWidget(row, 9)->setEnabled(false);
                        table->cellWidget(row, 10)->setEnabled(false);

                        QMessageBox::information(this, "改签成功",
                            QString("改签成功！\n新订单号：%1\n新车次座位已确认").arg(newOrder.getOrderId()));
                    }
                    });
            }
            row++;
        }
    }

    // 更新订单计数
    orderCountLabel->setText(QString("总计: %1 个订单").arg(orderCount));

    if (!hasOrder) {
        table->setRowCount(1);
        QTableWidgetItem* noOrderItem = new QTableWidgetItem("您还没有历史订单");
        noOrderItem->setTextAlignment(Qt::AlignCenter);
        noOrderItem->setForeground(QColor("#7f8c8d"));
        table->setItem(0, 0, noOrderItem);
        table->setSpan(0, 0, 1, colCount); // 合并单元格
        for (int i = 1; i < colCount; ++i) {
            table->setItem(0, i, new QTableWidgetItem(""));
        }
    }

    // 设置全局样式表
    setStyleSheet(R"(
        /* 主窗口样式 */
        QDialog {
            background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #f5f7fa, stop: 1 #e4e7ec);
            color: #333333;
        }

        /* 表格样式优化 */
        QTableWidget {
            background-color: white;
            border: 1px solid #e1e8ed;
            border-radius: 8px;
            gridline-color: #f0f0f0;
            outline: none;
        }
        QTableWidget::item {
            border: none;
            padding: 8px 12px;
            color: #2c3e50;
            border-bottom: 1px solid #f8f9fa;
        }
        QTableWidget::item:selected {
            background-color: #e3f2fd;
            color: #1565c0;
        }
        QTableWidget::item:hover {
            background-color: #f5f5f5;
        }
        QTableWidget::item:alternate {
            background-color: #fafbfc;
        }
        QHeaderView::section {
            background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #34495e, stop: 1 #2c3e50);
            color: white;
            padding: 12px 15px;
            border: none;
            font-weight: bold;
            border-right: 1px solid #455a64;
        }
        QHeaderView::section:last {
            border-right: none;
        }

        /* 滚动条样式 */
        QScrollBar:vertical {
            background: #f0f0f0;
            width: 12px;
            margin: 0px;
        }
        QScrollBar::handle:vertical {
            background: #c0c0c0;
            border-radius: 6px;
            min-height: 20px;
        }
        QScrollBar::handle:vertical:hover {
            background: #a0a0a0;
        }
        QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {
            height: 0px;
        }
    )");

    setLayout(mainLayout);
}
